package cn.mcmarket.yhstick;

import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class PlayerListener implements Listener {

    @EventHandler(priority = EventPriority.HIGH)
    private void onPlayerRightClick(PlayerInteractEvent e){
        if (e.isCancelled())return;
        if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK))return;
        if (!e.getClickedBlock().getType().equals(Material.CHEST))return;
        if (e.getItem()==null)return;
        if (!Yhstick.getInstance().isStick(e.getItem()))return;
        e.setCancelled(true);
        Chest c = (Chest) e.getClickedBlock().getState();
        Yhstick.getInstance().sellItems(c.getBlockInventory(),e.getPlayer(),e.getItem());

    }



}
